package com.xuecheng.learning.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xuecheng.commons.model.dto.PageRequest;
import com.xuecheng.commons.model.dto.WorkDto;
import com.xuecheng.commons.model.vo.PageResponseResult;
import com.xuecheng.commons.model.vo.ResponseResult;
import com.xuecheng.commons.model.vo.WorkVo;
import com.xuecheng.commons.utils.BeanHelper;
import com.xuecheng.learning.domain.Work;
import com.xuecheng.learning.mapper.WorkMapper;
import com.xuecheng.learning.service.WorkService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.print.Doc;
import java.util.List;

/**
 * <p>
 * 作业 服务实现类
 * </p>
 *
 * @author itheima
 * @since 2022-08-08
 */
@Service
public class WorkServiceImpl extends ServiceImpl<WorkMapper, Work> implements WorkService {
    //分页条件查询课程计划作业列表
    @Override
    public ResponseResult workList(PageRequest request, WorkDto dto) {
        // 课程计划作业分页查询
        // 1.构建分页
        Page<Work> page = new Page<>(request.getPageNo(), request.getPageSize());
        //构建分页条件
        LambdaQueryWrapper<Work> qw = new LambdaQueryWrapper<>();
        qw.eq(ObjectUtil.isNotEmpty(dto.getCoursePubId()),Work::getCoursePubId,dto.getCoursePubId());//课程发布id
        qw.eq(ObjectUtil.isNotEmpty(dto.getTeachplanId()),Work::getTeachplanId,dto.getTeachplanId());//课程计划id
        qw.eq(StrUtil.isNotBlank(dto.getTitle()),Work::getTitle,dto.getTitle());//标题
        qw.eq(StrUtil.isNotBlank(dto.getUsername()),Work::getUsername,dto.getUsername());//作业提交人
        qw.eq(ObjectUtil.isNotEmpty(dto.getStatus()),Work::getStatus,dto.getStatus());  //状态:使用态--1，删除态--0
        // 3.执行分页查询
         page=this.page(page,qw);
        long total = page.getTotal();
        List<Work> workList = page.getRecords();
        // 4.转vo
        List<WorkVo> voList = BeanHelper.copyWithCollection(workList, WorkVo.class);


        return PageResponseResult.okResult(total,voList);
    }
}
